﻿using Dapper.DBContext.Schema;
using Guoc.BigMall.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Guoc.BigMall.Application.DTO
{
   public class DistributeModel
    {
        public DistributeModel() {
            this.Items = new List<DistributeRebateModel>();
        }

         public int ProductId { get; set; }

         public string ProductCode { get; set; }

         public string ProductName { get; set; }

         public decimal SalePrice { get; set; }

         public decimal Rebate { get; set; }

        public List<DistributeRebateModel> Items { get; set; }

        /// <summary>
        /// 检查多级分润之和是否超过分润金额
        /// </summary>
        public void CheckLevelRebate() {
            var totalLevelRebate = this.Items.Sum(n => n.LevelRebate);
            if (totalLevelRebate > this.Rebate) {
                throw new FriendlyException("多级分销总金额不能大于分润金额!");
            }
        }
        
    }
    [Table("Distribute_rebate")]
    public class DistributeRebateModel
    {
        public int Id { get; set; }
        public int ProductId { get; set; }

        public int Level { get; set; }

        public decimal LevelRebate { get; set; }

    }
}
